package com.wondream.myframework.app.jade.http.request;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 分页查询对象.
 * <p>
 * create on 2023-07-24
 *
 * @author <a href="mailto:xianwei.wang@jadefortune.com.cn">wangxianwei</a>
 * @since 2.2.0
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("分页查询对象")
public final class PageQuery<T> {

    @Valid
    @NotNull(message = "queryParams不能为空")
    @ApiModelProperty(name = "queryParams", value = "查询参数对象", required = true)
    private T queryParams;

    @Valid
    @NotNull(message = "pageRequest不能为空")
    @ApiModelProperty(name = "pageRequest", value = "分页信息对象", required = true)
    private PageRequest pageRequest;

    /**
     * 构建分页查询对象
     *
     * @param queryParams 查询参数
     * @param pageRequest 分页参数
     * @return 分页查询对象
     */
    public static <T> PageQuery<T> of(T queryParams, PageRequest pageRequest) {
        return new PageQuery<>(queryParams, pageRequest);
    }

    /**
     * 构建分页查询对象
     *
     * @param queryParams 查询参数
     * @param page        页数
     * @param size        条数
     * @return 分页查询对象
     */
    public static <T> PageQuery<T> of(T queryParams, int page, int size) {
        return new PageQuery<>(queryParams, PageRequest.of(page, size));
    }

}
